package com.itfenghuang.day13;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class A09_复习2 {
    public static void main(String[] args) throws IOException {


        DatagramSocket socket = new DatagramSocket(12345);
        //创建数据报包
        byte[] bys=new byte[1024];
        DatagramPacket packet = new DatagramPacket(bys,bys.length);
        // 接受数据 到数据报包中
        socket.receive(packet);
        //获取数据报包中数据
        byte[] data = packet.getData();
        //获取数据报包中的数据长度
        int length = packet.getLength();
        System.out.println(length);

        String s = new String(data, 0,length);
        System.out.println(s);
        socket.close();

    }
}
